<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller{
    protected $_templates;
    public function __construct(){
        parent::__construct();
        $this->load->model('login_model','login_md');
    }
    /*
     * @Author : 
     * @Method : login
     * @param  :
     * @date   : 2/10/2012
     * @Modify : 
     */
    public function index(){  
        $user_name = $this->input->post('user_login');
        $password = md5($this->input->post('user_pass'));
        if($this->session->userdata('admin_id')){
//            redirect('admincp');
        }       
        $this->form_validation->set_rules('user_login',lang('login_name'),'trim|required|callback_check_login');
        $this->form_validation->set_rules('user_pass',lang('login_password'),'trim|required');
        if($this->form_validation->run()){
            if($this->login_md->get_admin($user_name,$password)){

                $this->session->set_flashdata('message',lang('login_success'));
                redirect(base_url().'admincp');
            }else{
                $this->session->set_flashdata('error',lang('login_unsuccess_recheck'));
            }
        }          
        $this->load->view('login/index');
    }
    /*
     * @author : 
     * @method : check login
     * @param  : $user_login - User name login
     * @date   : 2/10/2012
     * @modify : 
     */
    function check_login($user_login){
        $password= md5($this->input->post('user_pass'));
        if($user_login!=''&&$password!=''){
            if($this->login_md->check_login($user_login,$password)){
                return true;
            }else{
                $this->form_validation->set_message('check_login',lang('login_fail_info'));
                return false;
            }
        }else{
            $this->form_validation->set_message('check_login',lang('login_name_pass_not_empty'));
            return false;
        }
    }
    /*
     * @author : 
     * @method : logout
     * @param  : 
     * @date   : 2/10/2012
     * @modify : 
     */
    function logout(){
      $this->session->sess_destroy();
      redirect(base_url());          
    }       
}
/* End of file login.php */
/* Location: ./webadmin/controllers/login.php */
